import os, logging, random

from google.appengine.ext import webapp
from google.appengine.ext.webapp import template

from app_settings   import *
from utils          import *

class HomePage(webapp.RequestHandler):
    def get(self):
        logging.debug('GET request received, calling POST method...')
        self.post()

    def post(self):
        logging.debug('POST request received')
        password = get_random_password(random.randint(2,4))
        current_host = self.request.host
        if current_host in bad_domains:
            logging.debug('found [%s] in bad_doamins' % current_host)
            new_host = good_domains[random.randint(0, len(good_domains)-1)]
            logging.debug('redirect to new host: %s' % new_host)
            self.redirect(self.request.scheme+'://'+new_host)
        new_url = self.request.host_url + ('/r/like%s.html' % password)
        logging.debug('redirect to new url: %s' % new_url)
        self.redirect(new_url)
